﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "GbmpModel.h"
#include "Box3d.h"

namespace gcmp
{
    class IGraphicsElementShape;
    class IGraphicsNode;
    class IGraphicsNodeGroup;
    class IGraphicsBRepBody;
    class IDocument;
    class ICurve3d;

    enum class BodiesPositionTypes;

    // GRepUtils中平台不暴露的API
    class GBMP_MODEL_EXPORT GbmpGraphicsNodeUtils
    {
    public:
        static OwnerPtr<IGraphicsNodeGroup> TransferGRepToGGroup(OwnerPtr<IGraphicsElementShape> pGRep);

        //获取Body，只返回一个Body
        static OwnerPtr<IGraphicsBRepBody> GetGRepBody(const IDocument* pDoc, const IGraphicsElementShape* pGRep);
        static std::vector<OwnerPtr<IGraphicsBRepBody>> GetAllGrepBodys(const IDocument* pDoc, const IGraphicsElementShape* pGRep);

        static Box3d ExpandBox3dExceptZValue(Box3d &box, double size);

        //只求相交点，不含重合等情形的点
        static bool IntersectCurve3dsByExtend(const ICurve3d* pFirGmICurve3d, const ICurve3d* pSecGmICurve3d, std::vector<Vector3d>& ptIntersects);

        static bool IsIntersect(const IDocument* pDoc, const IGraphicsElementShape*pFirstGRep, const IGraphicsElementShape *pSecondGRep);
        static BodiesPositionTypes Intersect(const IDocument* pDoc, const IGraphicsElementShape*pFirstGRep, const IGraphicsElementShape *pSecondGRep, bool useBox = true);
        static BodiesPositionTypes Intersect(const IGraphicsBRepBody* pFirstBody, const IGraphicsBRepBody *pSecondBody);
        //获取所有Bodies
        static std::vector<OwnerPtr<IGraphicsBRepBody>> GetGRepBodies(const IDocument* pDoc, const IGraphicsElementShape* pGRep);

        static bool IsPointInsideOrOnBody(const IDocument* pDoc, const Vector3d& pos, const IGraphicsElementShape*pGRep);

        // 清除root和其下所有子节点的材质样式Id引用
        static bool ClearStyleAndMaterialReferenceInGraphicsNodeAndChildren(const IDocument* pDoc, IGraphicsNode* pRoot);

    };
}// namespace gcmp

